const pool = require("../connection/sqlPool");

async function GETTOPICF(attribute){
    const promisePool = pool.promise();
    try{
        const [rows,fields] = await promisePool.query('SELECT * FROM `Subject_manage` WHERE `attribute` = ?',[attribute]);
        //return rows
        return {topic:rows[0],now_num:rows[0].id+1};
    }catch(error){
        return {msg:error.message,attribute:attribute};
    }
    
}

async function GETTOPIC(now_num){
    const promisePool = pool.promise();
    try{
        const [rows,fildes] = await promisePool.query('SELECT * FROM `Subject_manage`WHERE `id` = ?',[now_num]);
        //return rows
        return {topic:rows[0],next_num:parseInt(now_num)+1};
    }catch(error){
        return {msg:error.message};
    }
}
module.exports = {GETTOPICF,GETTOPIC}